package com.lsp.concurrent.locks;

/*
 * 使用LSPReentrantLock类实现同步
 * */
class MyReenrantLock implements Runnable{
    //向上转型
    private LSPReentrantLock lock = new LSPReentrantLock();
    public void run() {
        //上锁
        lock.lock();
        for(int i = 0; i < 5; i++) {
            System.out.println("当前线程名： "+ Thread.currentThread().getName()+" ,i = "+i);
        }
        //释放锁
        lock.unlock();
    }
}

public class LockDemoTest {
    public static void main(String[] args)  {
        MyReenrantLock myReenrantLock =  new MyReenrantLock();
        Thread[] threads = new Thread[10];
        for (int i = 0; i < threads.length; i++){
            threads[i] = new Thread(myReenrantLock);
            threads[i].start();
        }
    }
}

